<template>
  <div class="score_list">
    <ScoreComponent
      v-if="emitList && emitList.children"
      :scoreData="emitList.children"
      :disabled="disabled"></ScoreComponent>
  </div>
</template>

<script>
import ScoreComponent from './ScoreComponent'
export default {
  name: 'ScoreList',
  components: { ScoreComponent },
  props: {
    scoreList: {
      type: Object,
      default: () => {
        return {}
      },
    },
    disabled: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      emitList: {},
    }
  },
  computed: {},
  watch: {
    scoreList: {
      handler(news) {
        // console.log('news :>> ', news)
        const data = JSON.parse(JSON.stringify(news))
        if (news.busId) {
          this.emitList = data
        } else {
          this.emitList = {}
        }
      },
      deep: true,
      immediate: true,
    },
  },
  created() {},
  mounted() {},
  methods: {
    getData() {
      const flag = this.judgeData(this.emitList)
      if (flag) {
        this.$emit('scoreSubmit', JSON.parse(JSON.stringify(this.emitList)))
      } else {
        this.$toast.fail('请完成所有评价及相关备注说明之后再进行提交')
      }
    },
    judgeData(data) {
      let flag = true
      if (data.children && data.children.length) {
        for (let i = 0; i < data.children.length; i++) {
          const el = data.children[i]
          if (el.children && el.children.length) {
            flag = this.judgeData(el)
            if (!flag) break
          } else {
            if (!el.checkOptionId || (this.showRemark(el) && !el.remark)) {
              flag = false
              break
            }
          }
        }
      }
      return flag
    },
    showRemark(item) {
      const len = item.optionList.length
      const list = item.optionList
      const optionId1 = list[len - 1].optionId
      const optionId2 = list[len - 2].optionId
      if ([optionId1, optionId2].includes(item.checkOptionId)) {
        return true
      } else {
        return false
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.score_list {
  padding: 0 2px;
  font-size: 14px;
  margin-bottom: 10px;
}
</style>
